package com.xym.web.Service;

import java.io.IOException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.xym.pojo.User;

@Service
public class UserService {

	@Autowired
	private ApiService apiService;
	
	public static final String SSO_TAOTAO_BASE_URL = "http://sso.xym.com";

	/**
	 * 调用httpclient 访问sso 查询用户登录信息
	 * @param token
	 * @return
	 */
	public User queryUserByToken(String token) {
		
		String uri = SSO_TAOTAO_BASE_URL+"/user/query/"+token+".html";
		try {
			String userJson = apiService.doGet(uri);
			return new ObjectMapper().readValue(userJson,User.class );
		
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}

}
